<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<title></title>
		<link rel="stylesheet" href="css/font.css" />
		<link rel="stylesheet" href="css/common.css" />
		<link rel="stylesheet" href="css/user.css" />
		<link rel="stylesheet" href="aPlugin/EasyDropDown/themes/easydropdown.css" />
		<script type="text/javascript">
			document.addEventListener('plusready', function() {
				//console.log("所有plus api都应该在此事件发生后调用，否则会出现plus is undefined。"

			});
		</script>

	</head>
	<body>
		<header class=" header-module ">
			<div class="flex-justify-align header-top">
				<a href="javascript:history.go(-1);" class="iconfont iconfanhuijiantou header-back"></a>
				<p class="header-title">保险提报</p>
				<span class="header-span"></span>
			</div>

		</header>
		<article class="middle-moudle">

			<section class="base-interval user-module ">
				<form id="companyForm">
					<input type="hidden" name="companyId" id="companyId" />
					<input type="hidden" name="declareTypeId" id="declareTypeId" />
					<input type="hidden" name="insuranceId" id="insuranceId" />
					<input type="hidden" name="companyId" id="companyId" />
					<div class="user-item">
						<p>需求金额</p>
						<input type="text" name="money" id="money" placeholder="请输入需求金额">
					</div>
					<div class="user-item">
						<p>需求描述</p>
						<textarea cols="52" rows="10" type="text" name="remark" id="remark" placeholder="请输入需求描述"></textarea>
					</div>
					<div class="user-item">
						<button class="user-btn" type="button" onclick="submitDeclare()" id="submit">提报</button>
					</div>
				</form>
			</section>
		</article>
	</body>
	<script src="js/jquery-3.0.0.min.js"></script>
	<script src="js/gloab.js"></script>
	<script>
		$(function() {
			var id = getUrlParam('id');
			var iid = getUrlParam('iid');
			$("#declareTypeId").val(id);

			var company = JSON.parse(localStorage.getItem("company"));
			if (!company) {
				window.location.href = "login.html"
			}
			$("#companyId").val(company.id);
		});

		//获取url中的参数
		function getUrlParam(name) {
			var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
			var r = window.location.search.substr(1).match(reg); //匹配目标参数
			if (r != null) return unescape(r[2]);
			return null; //返回参数值
		};

		//提报,信息保存.
		function submitDeclare() {
			// 点击后，禁用提交
			$("#submit").attr("disabled", true);

			var money = $("#money").val();
			var remark = $("#remark").val();
			if (money == '' || remark == '') {
				// 返回,解开提交禁用
				$("#submit").attr("disabled", false);
				alert("提报信息请填写完全。");
				return;
			}

			$.ajax({
				//请求方式    
				type: "GET",
				//文件位置    
				url: basePath + "app/tdeclare/submitDeclare",
				//返回数据格式为json,也可以是其他格式如    
				dataType: "json",
				data: $("#companyForm").serialize(),
				//请求成功拼接html    
				success: function(data) {
					// 返回,解开提交禁用
					$("#submit").attr("disabled", false);
					if (data.msg == "success") {
						alert("提报成功！")
						window.location.href = "apply.html";
					} else {
						alert("提报失败！")
					}
				},
				error: function() {
					alert("提报发生错误！")
				},
				complete: function(XMLHttpRequest, status) { //当请求完成时调用函数
					// 返回,解开提交禁用
					$("#submit").attr("disabled", false);
				}
			});
		}
	</script>
	<script src="aPlugin/EasyDropDown/jquery.easydropdown.min.js"></script>
</html>
